package com.chilly.other.collection.map;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 添加到SortedMap实现类（TreeMap）的元素必须实现Comparable接口，
 * 否则您必须给它的构造函数提供一个Comparator接口的实现
 * <p>
 * Created by Chilly Cui on 2020/12/15.
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
@ToString
public class Person implements Comparable {
    private String name;
    private Integer age;

    @Override
    public int compareTo(Object o) {
        Person p = (Person) o;
        if (this.age > p.age) {
            return 1;
        } else if (this.age < p.age) {
            return -1;
        }
        return 0;
    }
}
